package com.wuyan.locationdog.ui.my

import android.os.Bundle
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.arcsoft.commonbase.base.BaseBindingActivity
import com.arcsoft.commonbase.ext.createEmptyView
import com.blankj.utilcode.util.ActivityUtils
import com.wuyan.locationdog.R
import com.wuyan.locationdog.adapter.WorkOrderListAdapter
import com.wuyan.locationdog.databinding.MyFeedbackListActivityBinding
import com.wuyan.locationdog.help.finishRefreshAndLoadMoreNoMoreData
import com.wuyan.locationdog.viewmodel.MyViewModel


class MyFeedbackListActivity : BaseBindingActivity<MyFeedbackListActivityBinding>() {
    private val mViewModel: MyViewModel by viewModels()

    private val mAdapter by lazy { WorkOrderListAdapter(R.layout.item_suggest_list, null) }

    override fun initData() {
        setTitleText("我的反馈")


        binding.apply {
            setOnRefreshLoadMore(smartRefreshLayout)


            recyclerView.apply {
                layoutManager = LinearLayoutManager(context)
                adapter = mAdapter.apply {
                    setEmptyView(createEmptyView("暂无反馈"))


                    setOnItemClickListener { adapter, view, position ->
                        val bundle = Bundle()
                        bundle.putString("workOrderId", data[position].workOrderId.toString())
                        ActivityUtils.startActivity(bundle, MyFeedbackDetailActivity::class.java)

                    }
                }
            }


        }



    }

    override fun loadNetData() {
        super.loadNetData()
        val map = HashMap<String, Any>()
        map["pageNum"] = currentPage
        map["pageSize"] = 10
//        map["workOrderType"] = 1//反馈类型(1问题反馈 2产品建议)

        mViewModel.workOrderList(map)
    }
    override fun observe() {
        super.observe()

        mViewModel.workOrderBean.observe(this) {

            finishRefreshAndLoadMoreNoMoreData(binding.smartRefreshLayout, currentPage, it.total)
            if (currentPage == 1) {
                mAdapter.setNewInstance(it.content.toMutableList())
            } else {
                mAdapter.addData(it.content.toMutableList())
            }        }
    }

}